package com.blacktry.controller.es;

import com.blacktry.entity.model.request.ArticlesRequest;
import com.blacktry.service.BLogESService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Api(tags = "BlogES管理接口")
@RestController("/ESBlog")
public class BlogESController {
    @Autowired
    private BLogESService bLogESService;


    @ApiOperation(value = "抓取关键词数据")
    @GetMapping("/parse")
    public Boolean parse() throws Exception {
        return bLogESService.parseContent();
    }

    // 在es中搜索数据返回结果
    @ApiOperation(value = "ES高亮搜寻结果")
    @PostMapping("/search/{pageNo}/{pageSize}")
    public List<Map<String, Object>> search(@PathVariable("pageNo") int pageNo,
                                            @PathVariable("pageSize") int pageSize,
                                            @RequestBody ArticlesRequest articlesRequest) throws IOException {
        return bLogESService.HighSearchPage(articlesRequest, pageNo, pageSize);
    }



    // 在es中搜索数据返回结果
    public List<Map<String, Object>> searchOther(@PathVariable("keyword") String keyword,
                                            @PathVariable("pageNo") int pageNo,
                                            @PathVariable("pageSize") int pageSize) throws IOException {
        HashMap<String, Object> map = new HashMap<>();
        map.put("空","暂无数据");
        List list = new LinkedList<>();
        list.add(map);
        return list;
    }



    @ApiOperation(value = "创建一个索引")
    @GetMapping("/create")
    void createIndex() throws IOException {
        bLogESService.createIndex();
    }
}